package com.phlic.controller;




import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Controller
public class HelloController {
    @RequestMapping("/index")
    public String sayHello(){
        return "index";
    }


    /**
     * 删除通道门
     * @param response
     * @throws IOException
     */
    @ResponseBody
    @RequestMapping(value = "op", method = RequestMethod.GET)
    public Map<String,Object> delMiJiJiaTDM(HttpServletResponse response, HttpServletRequest request) throws IOException{
        Map<String,Object> map=new HashMap<>();
        String ip=request.getParameter("ip");
        String ret=Jaxtest(ip);
        map.put("msg",ret);
        return map;
    }

    public static void main(String[] args) throws IOException, InterruptedException {

        Jaxtest("192.168.1.124");
    }

    public static String Jaxtest(String ip){
        String ret="-1";
        try {
            JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();

            Client client = dcf.createClient("http://"+ip+":9000/MjjService?wsdl");
            Object[] objects1= client.invoke("GetQuXX"); //参数1，参数2，参数3......按顺序放就看可以
            System.out.println(objects1[0].toString()+"科达===。。。。。。。。" +ip);
            if(objects1!=null&&!objects1[0].toString().equals("")){
                ret=objects1[0].toString();
            }
        } catch (Exception e) {
            //System.out.println("科达股份pay打破伤风大跑商有回复===。。。。。。。。" +ip);
            e.printStackTrace();

        }
        return ret;
    }

}
